home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libio / stdstrbufs.cc < prev    next >
C/C++ Source or Header  |  1994-06-24  |  3KB  |  90 lines

  1. /* 
  2. Copyright (C) 1994 Free Software Foundation
  3.  
  4. This file is part of the GNU IO Library.  This library is free
  5. software; you can redistribute it and/or modify it under the
  6. terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU CC; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. As a special exception, if you link this library with files
  20. compiled with a GNU compiler to produce an executable, this does not cause
  21. the resulting executable to be covered by the GNU General Public License.
  22. This exception does not however invalidate any other reasons why
  23. the executable file might be covered by the GNU General Public License. */
  24.  
  25.  
  26. /* This file provides definitions of _IO_stdin, _IO_stdout, and _IO_stderr
  27.    for C++ code.  Compare stdfiles.c.
  28.    (The difference is that here the vtable field is set to
  29.    point to builtinbuf's vtable, so the objects are effectively
  30.    of class builtinbuf.) */
  31.  
  32. #include "libioP.h"
  33. #include <stdio.h>
  34.  
  35. #ifndef STD_VTABLE
  36. #define STD_VTABLE builtinbuf_vtable
  37. #endif
  38.  
  39. #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
  40.   struct _IO_FILE_plus NAME = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), STD_VTABLE}
  41.  
  42. DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
  43. DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_.file, _IO_NO_READS);
  44. DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_.file,
  45.             _IO_NO_READS+_IO_UNBUFFERED);
  46.  
  47. #ifdef _STDIO_USES_IOSTREAM
  48. _IO_FILE *_IO_list_all = &_IO_stderr_.file;
  49. #else /* !_STDIO_USES_IOSTREAM */
  50. #include "stdiostream.h"
  51.  
  52. struct _IO_fake_stdiobuf {
  53.   _IO_FILE file;
  54.   const void *vtable;
  55.   FILE *stdio_file;
  56. };
  57.  
  58. /* Define stdiobuf_vtable as a name for the virtual function table
  59.    of the stdiobuf class. */
  60. #ifndef stdiobuf_vtable
  61. #ifdef __GNUC__
  62. extern char stdiobuf_vtable[]
  63.   asm (_G_VTABLE_LABEL_PREFIX
  64. #if _G_VTABLE_LABEL_HAS_LENGTH
  65.        "8"
  66. #endif
  67.        "stdiobuf");
  68. #else /* !__GNUC__ */
  69. #if _G_VTABLE_LABEL_HAS_LENGTH
  70. #define stdiobuf_vtable _G_VTABLE_LABEL_PREFIX_ID##8stdiobuf
  71. #else
  72. #define stdiobuf_vtable _G_VTABLE_LABEL_PREFIX_ID##stdiobuf
  73. #endif
  74. extern char stdiobuf_vtable[];
  75. #endif /* !__GNUC__ */
  76. #endif /* !stdiobuf_vtable */
  77.  
  78. #define DEF_STDIOFILE(NAME, FD, FILE, FLAGS, CHAIN) \
  79.   struct _IO_fake_stdiobuf NAME = \
  80.       {{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+_IO_UNBUFFERED+FLAGS, \
  81.          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, &_IO_streambuf_jumps, FD},\
  82.          stdiobuf_vtable, FILE}
  83.  
  84. DEF_STDIOFILE(_IO_stdin_buf, 0, stdin, _IO_NO_WRITES, &_IO_stderr_.file);
  85. DEF_STDIOFILE(_IO_stdout_buf, 1, stdout, _IO_NO_READS, &_IO_stdin_buf.file);
  86. DEF_STDIOFILE(_IO_stderr_buf, 2, stderr, _IO_NO_READS, &_IO_stdout_buf.file);
  87.  
  88. _IO_FILE *_IO_list_all = &_IO_stderr_buf.file;
  89. #endif  /* !_STDIO_USES_IOSTREAM */
  90.